"""
多线程带来的安全问题
"""

import threading


num = 50


def sub():
    """
    线程函数
    """
    global num
    for _ in range(1000):
        if num > 0:
            print(f'子线程{threading.current_thread().name}执行结束，num={num}')
            num -= 1


if __name__ == '__main__':
    print('开始前...：num =', num)

    items = [threading.Thread(target=sub) for _ in range(3)]

    for item in items:
        item.start()
        item.join()

    print('结束后：num =', num)
